﻿using MongoDB.Driver;

namespace nMongo
{
    public partial class MongoRepository<T>
    {
        /// <summary>
        /// (CAUTION) Delete all objects in the current collection.
        /// </summary>
        /// <returns>bool: if all objects were been deleted with success; false: if all objects were not been deleted with success.</returns>
        public bool DeleteAll()
        {
            WriteConcernResult result;
            return DeleteAll(out result);
        }

        /// <summary>
        /// (CAUTION) Delete all objects in the current collection.
        /// </summary>
        /// <param name="result">WriteConcernResult object to receive the operation result.</param>
        /// <returns>bool: if all objects were been deleted with success; false: if all objects were not been deleted with success.</returns>
        public bool DeleteAll(out WriteConcernResult result)
        {
            return DeleteAll(WriteConcern.Acknowledged, out result);
        }

        /// <summary>
        /// (CAUTION) Delete all objects in the current collection.
        /// </summary>
        /// <param name="concern">Type of WriteConcern to be acknownledged.</param>
        /// <param name="result">WriteConcernResult object to receive the operation result.</param>
        /// <returns>bool: if all objects were been deleted with success; false: if all objects were not been deleted with success.</returns>
        public bool DeleteAll(WriteConcern concern, out WriteConcernResult result)
        {
            result = OriginalCollection.RemoveAll(concern);
            return (result != null && result.Ok);
        }
    }
}
